#include <unistd.h>
#include <sstream>
#include "Pizzeria/Tests/WalkieTalkie_tests.hpp"
#include "Pizzeria/Communication/WalkieTalkie.hpp"
#include "Pizzeria/Pizza.hpp"

namespace pizzeria {

WalkieTalkie_tests::WalkieTalkie_tests()
    : mTestRunner("WalkieTalkie's tests")
{
  mTestRunner.AddTestCase(
      UTESTS_MAKE_CASE_DATA(WalkieTalkie_tests::SerializationTests));
  mTestRunner.Run(true);
}

WalkieTalkie_tests::~WalkieTalkie_tests() {

}

UTESTS_START_TEST(WalkieTalkie_tests::SerializationTests)
  {
    communication::WalkieTalkie wA;
    communication::WalkieTalkie wB;

    wA.LinkWith(wB);
    Pizza pizza(Pizza::Fantasia, Pizza::XL);
    communication::Message msgSend(communication::Message::NEW_ORDER, &pizza);
    wA.Send(msgSend);
    communication::Message msgReceive = wB.Receive();
    UTESTS_FAIL_UNLESS(msgReceive.GetType() == msgSend.GetType(),
	"Serialization type failed");
    const Pizza *receivedPizza =
	static_cast<const Pizza *>(msgReceive.GetData());
    UTESTS_FAIL_UNLESS(receivedPizza->GetType() == pizza.GetType(),
	"Serialization data failed");
    UTESTS_FAIL_UNLESS(receivedPizza->GetSize() == pizza.GetSize(),
	"Serialization data failed");
  }
  UTESTS_END_TEST

} /* namespace pizzeria */
